//
// Created by lm379 on 25-3-11.
//
#include<iostream>
using namespace std;

typedef struct LNode {
    int data;
    LNode *next;
} LNode;

void delItems(const LNode *L) {
    LNode *p = L -> next;
    while (p->next != nullptr) {
        if (p -> data == p-> next -> data) {
            LNode *q = p->next;
            p -> next = q -> next;
            free(q);
        } else {
            p = p -> next;
        }
    }
}

void CreateList(LNode *&head, const int arr[], const int length) {
    head = static_cast<LNode *>(malloc(sizeof(LNode)));
    head -> next = nullptr;
    LNode *p = head;
    for (int i = 0; i < length; i++) {
        auto *q = static_cast<LNode *>(malloc(sizeof(LNode)));
        q -> data = arr[i];
        q -> next = nullptr;
        p -> next = q;
        p = q;
    }
}

void Split(LNode *A,LNode *&B) {
    LNode *p,*q,*r;
    B = static_cast<LNode *>(malloc(sizeof(LNode)));
    B -> next = nullptr;
    r = B;
    p = A -> next;
    while (p != nullptr) {
        if (p -> data % 2 ==0) {
            q = p;
            r -> next = q;
            p -> next = q -> next;
            q -> next = nullptr;
            r = q;
        } else {
            p = p -> next;
        }
    }
}

void PrintList(const LNode *L) {
    const LNode *p = L -> next;
    while (p != nullptr) {
        cout << p -> data << " ";
        p = p -> next;
    }
    cout << endl;
}

int main() {
    const int arr[] = {1,1,2,3,3,3,4,4,5,6,7,7,7,8,8,8,9,9,9};
    constexpr int length = std::size(arr);
    LNode *L = nullptr;
    CreateList(L, arr, length);
    delItems(L);
    PrintList(L);
    // LNode *B = nullptr;
    // Split(L, B);
    // PrintList(L);
    // PrintList(B);
    return 0;
}